﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FrameWork.BLL;
using FrameWork.Entity;
using FrameWork.Common;
using System.Collections.Generic;
#foreach($u in $TableInfos)
#beforeall 
#each 
namespace FrameWork.Web.Web.Manager.NormalApp.${u.TabName}Manager
{
    public partial class Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                BindData();
            }
        }
 
        protected void  btnSearch_Click(object sender, EventArgs e)
        {
#foreach($c in $u.ColumnInfos)  
#beforeall
#each 
#if($c.IsPK!="True")
#if($c.TypeCSharpName=="DateTime")
            $c.TypeCSharpName? str$c.ColumnName =($c.TypeCSharpName?) Utils.GetQueryAndFormString(tb$c.ColumnName .UniqueID, MethodType.Post, $c.Length, 0,DataType.$c.TypePostName); 
#else
            $c.TypeCSharpName str$c.ColumnName =($c.TypeCSharpName) Utils.GetQueryAndFormString(tb$c.ColumnName .UniqueID, MethodType.Post, $c.Length, 0,DataType.$c.TypePostName); 
#end
#end
#afterall
#end 
            string SqlSearch = " 1=1";
#foreach($c in $u.ColumnInfos)  
#beforeall
#each 
#if($c.IsPK!="True")
             if (str$c.ColumnName != $c.DefaultValCSharp)
            {
                SqlSearch =string.Concat(SqlSearch, " and $c.ColumnName like '%" , str$c.ColumnName , "%'");
            }
#end
#afterall
#end 
            ViewState["SearchTerms"] = SqlSearch;
            BindData();
            TabOptionWebControls1.SelectIndex = 0;
        }


        private void BindData()
        {
            QueryParam qp = new QueryParam();
            qp.PageIndex = AspNetPager1.CurrentPageIndex;
            qp.PageSize = AspNetPager1.PageSize;
            qp.Where = SearchTerms;
           
            int RecordCount = 0;
            List<${u.TabName}Entity> lst = BLLHelper.${u.TabName}List(qp, out RecordCount);
            GridView1.DataSource = lst;
            GridView1.DataBind();
            this.AspNetPager1.RecordCount = RecordCount;
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
#afterall
#end 
        /// <summary>
        /// 查询条件
        /// </summary>
        private string SearchTerms
        {
            get
            {
                if (ViewState["SearchTerms"] == null)
                    ViewState["SearchTerms"] = "";
                return (string)ViewState["SearchTerms"];
            }
            set { ViewState["SearchTerms"] = value; }
        }
    }
}

